package com.etlmaster.rowprocessor.core;

import java.util.Map;
import com.etlmaster.executor.utils.DpExecutorUtils;
import com.etlmaster.rowprocessor.disruptor.readEvent.LineEvent;
import com.etlmaster.rowprocessor.transformer.Line;
import com.etlmaster.rowprocessor.utils.ReflectionUtil;

/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public abstract class AbstractPlugin {
	private String id,name, code,jobId;
	private long counter;
	private long errorCounter;
	private Map<String,Object> variables;
	private volatile boolean stopFlag;

	public AbstractPlugin(String id,String jobId,String name,String code,Map<String,Object> paramMap,Map<String,Object> variables){
		this.id=id;
		this.setJobId(jobId);
		this.name=name;
		this.code=code;
 
		ReflectionUtil.parseParam(paramMap,this);
 
		this.setVariables(variables);
		ReflectionUtil.parseParam(paramMap,this);//会被子类的属性初始化覆盖，放在子类的构造器中
 
	}
	
	protected abstract void init();

	protected abstract void stop();
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public long getCounter() {
		return counter;
	}

	public void setCounter(long counter) {
		this.counter = counter;
	}


	public void onEvent(LineEvent event, long sequence, boolean endOfBatch) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void read(Line line) {
		// TODO Auto-generated method stub
	}

	public String getJobId() {
		return jobId;
	}

	public void setJobId(String jobId) {
		this.jobId = jobId;
	}

	public Map<String,Object> getVariables() {
		return variables;
	}

	public void setVariables(Map<String,Object> variables) {
		this.variables = variables;
	}
	protected String variableSubstution(String text){
		return DpExecutorUtils.variableSubstitution(text, variables);
	}

	public boolean isStopFlag() {
		return stopFlag;
	}

	public void setStopFlag(boolean stopFlag) {
		this.stopFlag = stopFlag;

	}

	public long getErrorCounter() {
		return errorCounter;
	}

	public void setErrorCounter(long errorCounter) {
		this.errorCounter = errorCounter;
	}

}
